/**
 * 2014-8-15下午7:04:44
 */
package com.sondon.mayi.ui;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.sondon.mayi.fruit.R;

/**
 * @ClassName: Picture_PopupWindows
 * @package com.mayi.july.pop
 * @author mayi
 * @date 2014-8-15 下午7:04:44
 * @Description: TODO(选择图片来源:照相机或者相册)
 * @version 1.0
 */
public class Picture_PopupWindows extends PopupWindow {
	private PicturePopClickListener picturePopClickListener;

	public Picture_PopupWindows(Context context, View parent) {
		initView(context, parent);

	}

	public void initView(Context context, View parent) {
		// 加载布局文件
		View view = View.inflate(context, R.layout.item_popupwindows, null);
		// 设置view的动画
		view.startAnimation(AnimationUtils.loadAnimation(context,
				R.anim.fade_ins));
		// 获取view中的控件
		LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
		// 开始view的动画
		ll_popup.startAnimation(AnimationUtils.loadAnimation(context,
				R.anim.push_bottom_in_2));

		setWidth(LayoutParams.MATCH_PARENT);
		setHeight(LayoutParams.MATCH_PARENT);
		// 添加下面的代码会出现阴影效果
		setBackgroundDrawable(new BitmapDrawable());
		setFocusable(true);
		setOutsideTouchable(true);
		setContentView(view);
		showAtLocation(parent, Gravity.BOTTOM, 0, 0);

		// Updates the state of the popup window
		update();

		Button camera_butt = (Button) view
				.findViewById(R.id.item_popupwindows_camera);
		Button Photo_butt = (Button) view
				.findViewById(R.id.item_popupwindows_Photo);
		Button cancel_butt = (Button) view
				.findViewById(R.id.item_popupwindows_cancel);

		// 点击事件
		camera_butt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (picturePopClickListener != null) {
					picturePopClickListener.PopCameraClick();
				}
			}
		});
		Photo_butt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (picturePopClickListener != null) {
					picturePopClickListener.PopPhotoClick();
				}
			}
		});
		cancel_butt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
	}

	/**
	 * 
	 * @Author 蔡文锋
	 * @Data_Time 2015年6月13日 上午9:47:09
	 * @Description {监听事件}
	 * @param listener
	 */
	public void SetPictureOnClickListener(PicturePopClickListener listener) {
		this.picturePopClickListener = listener;
	}
}
